<template>
  <div>
    <div class="bscroll" ref="bscroll0">
      <div class="bscroll-container">
        <!-- <div id="mycanvas" ref="mycanvas"></div> -->
        <iframe :src="pdf" frameborder="0"></iframe>
        <!-- <a :href="pdf">asda</a> -->
      </div>
    </div>
  </div>
</template>

<script>
import BScroll from "better-scroll";
// import pdf from "../../../static/pdf/build/pdf";
import { Indicator, Toast } from "mint-ui";
export default {
  data() {
    return {
      pdf: "" // pdf文件地址
    };
  },
  mounted() {
    let { id } = this.$route.query;
    let params = {
      id
    };
    this.$get("qrySmallCourseInfo", params).then(res => {
      if (res.success) {
        this.pdf = 'http://121.199.63.66:8080/app/static/pdf/web/viewer.html?file=' + res.data.filePath;
        // this.$nextTick(() => {
        //   this.getPdf(res.data.filePath);
        // });
      }
    });
    // better-scroll初始化
    this.initScroll("bscroll0");
  },
  methods: {
    initScroll(dom) {
      this.$nextTick(() => {
        let bscrollDom = this.$refs[dom];
        console.log(bscrollDom);
        this.aBScroll = new BScroll(bscrollDom, {
          click: true
        });
      });
    },
    // getPage(pdf, pageNumber, container, numPages) {
    //   console.log(pdf, pageNumber, container, numPages)
    //   //获取pdf
    //   let _this = this;
    //   pdf.getPage(pageNumber).then(page => {
    //     let scale = container.offsetWidth / page.view[2];
    //     let viewport = page.getViewport(scale);
    //     let canvas = document.createElement("canvas");
    //     canvas.width = viewport.width;
    //     canvas.height = viewport.height;
    //     container.appendChild(canvas);
    //     let ctx = canvas.getContext("2d");
    //     var renderContext = {
    //       canvasContext: ctx,
    //       transform: [1, 0, 0, 1, 0, 0],
    //       viewport: viewport,
    //       intent: "print"
    //     };
    //     page.render(renderContext).then(() => {
    //       pageNumber += 1;
    //       if (pageNumber <= numPages) {
    //         _this.getPage(pdf, pageNumber, container, numPages);
    //       }
    //     });
    //   });
    // },
    // getPdf(pdfFile) {
    //   // 此中方式接受流形式返回
    //   this.$refs.mycanvas.scrollTop = 0;
    //   let url = pdfFile;
    //   let pdfjsLib = pdf;
    //   pdfjsLib.PDFJS.workerSrc = "../../../static/pdf/build/pdf.worker.js";
    //   let loadingTask = pdfjsLib.getDocument(url);
    //   loadingTask.promise.then(
    //     pdf => {
    //       let numPages = pdf.numPages;
    //       let container = document.getElementById("mycanvas");
    //       let pageNumber = 1;
    //       this.getPage(pdf, pageNumber, container, numPages);
    //     },
    //     function(reason) {
    //       alert(reason);
    //     }
    //   );
    // }
  }
};
</script>
<style lang="less" scoped>
iframe{
  width: 100vw;
  height: 100vh;
}
.arrow {
  text-align: center;
}
</style>